package mmoon.mmoonstory.items;

import mmoon.mmoonstory.interfaces.InitItem;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;

public class ItemCatapult extends Item implements InitItem {
    public static final String ObjID = "catapult";

    public ItemCatapult() {
        super();
        this.setMaxStackSize(1);
        this.init(ObjID);
    }

    @Override
    public boolean onLeftClickEntity(ItemStack stack, EntityPlayer player, Entity entity) {
        // 左击生物使其飞天
        if (!entity.world.isRemote) {
            entity.motionX += (entity.posX - player.posX) * 10;
            entity.motionY += (entity.posY - player.posY) * 10 + 2.5;
            entity.motionZ += (entity.posZ - player.posZ) * 10;
            return true;
        }
        return false;
    }

    @Override
    public boolean onBlockStartBreak(ItemStack itemstack, BlockPos pos, EntityPlayer player) {
        // 不能挖不透明方块
        return !player.world.isRemote;
    }
}
